package com.vt.common.security.handler;

import org.springframework.context.ApplicationListener;
import org.springframework.security.authentication.event.AbstractAuthenticationFailureEvent;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;

/**
 * @Auther: PanZha
 * @Date: 2018/10/12 16:23
 * 认证失败事件处理器
 */
public abstract class AuthenticationFailureEvenHandler implements ApplicationListener<AbstractAuthenticationFailureEvent> {

    @Override
    public void onApplicationEvent(AbstractAuthenticationFailureEvent event) {
        Authentication authentication = (Authentication) event.getSource();
        AuthenticationException authenticationException = event.getException();

        handle(authentication, authenticationException);
    }

    /**
     * 处理登录失败方法
     *
     * @param authentication 登录的authentication 对象
     */
    public abstract void handle(Authentication authentication, AuthenticationException authenticationException);
}
